package com.study.ws.util.executor;

import org.springframework.boot.task.ThreadPoolTaskExecutorBuilder;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

/**
 * @author xl-9527
 * @since 2025/3/29
 **/
public class TheadPoolUtil {


    public static ThreadPoolTaskExecutor getTaskExecutor(int coreAndMax, String prefix) {
        return getTaskExecutor(coreAndMax, coreAndMax, prefix);
    }

    public static ThreadPoolTaskExecutor getTaskExecutor(int core, int max, String prefix) {
        return getTaskExecutor(core, max, 100, prefix);
    }

    public static ThreadPoolTaskExecutor getTaskExecutor(int core, int max, int queueSize, String prefix) {
        final ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutorBuilder()
                .maxPoolSize(max)
                .corePoolSize(core)
                .queueCapacity(queueSize)
                .threadNamePrefix(prefix)
                .build();

        taskExecutor.initialize();
        return taskExecutor;
    }
}
